# -*- coding: utf-8 -*-
import sys
import conf

try:
    import pygtk
    pygtk.require("2.0")
    import gtk
    import gtk.glade    
except ImportError,cause:
    sys.stderr.write("ImportError: Module is not present %s" % cause)
    sys.exit(1)
    
class UIManager(object):
    def __init__(self,root):
        # automate the glade conf process
        self.filename = "twicage" 
        self.gladefile = conf.GLADE_DIR + "/%s.glade" % self.filename
        self.wTree = gtk.glade.XML(self.gladefile,root)
        self.signals_dic = {}

    # get widgets from glade file
    def widget(self,widget_name):
        return self.wTree.get_widget(widget_name)

    # add  dictionary with connections
    def add_signal(self,sig_dic):
        if len(sig_dic) == 0: raise TypeError,"no signals included"
        self.signals_dic.update(sig_dic)
   
    # connect a single signal
    def signal_connect(self,signal,cb):
        if not signal or not cb: raise TypeError, "no signals included"
        self.wTree.signal_connect(signal,cb)

    # connect all signals and ready to go
    def signals_connect(self):
        if len(self.signals_dic) == 0: raise TypeError,"signals dic are empty"
        self.wTree.signal_autoconnect(self.signals_dic)

